<?
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/07/07 18:08:00 $)
// $RCSfile: report_popularsteps.php,v $ : $Revision: 1.1 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

$_categories = array();
$_viewcount = 0;
$_limit = 15;

if ($_GET["do"] == "chart")
{
	$_limit = 5;
}

$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."troubleshootersteps` ORDER BY `views` DESC LIMIT ". intval($_limit) .";");
while ($dbCore->nextRecord())
{
	$_categories[$dbCore->Record["troubleshooterid"]] = $dbCore->Record;
	$_viewcount += $dbCore->Record["views"];
}

/**
* ###############################################
* SHOW CHART?
* ###############################################
*/
if ($_GET["do"] == "chart")
{
	$chart['chart_bg'] = array('positive_alpha' => 0);
	// Prepeare the data
	$_chartdata = array("");
	$_chartvalues = array("");
	$_seriesexplode = array();
	$index = 0;
	foreach ($_categories as $key=>$val)
	{
		$_chartdata[] = substr($val["subject"],0,12);
		if (!empty($val["views"]))
		{
			$_chartvalues[] = ($val["views"]/$_viewcount)*100;
		} else {
			$_chartvalues[] = 0;
		}

		if ($index == 0)
		{
			$_seriesexplode[] = 15;
		} else if ($index == 1) {
			$_seriesexplode[] = 10;
		} else {
			$_seriesexplode[] = 0;
		}

		$index++;
	}

	$chart['chart_data'] = array($_chartdata, $_chartvalues);
	$chart['chart_grid_h'] = array('thickness' => 0);
	$chart['chart_rect'] = array('x' => 0, 'y' => 15, 'width' => 250, 'height' => 150);
	$chart['chart_type'] = "3d pie";
	$chart['chart_value'] = array('color' => "000000", 'alpha' => 65, 'font' => "verdana", 'bold' => true, 'size' => 10, 'position' => "inside", 'prefix' => "", 'suffix' => "", 'decimals' => 0, 'separator' => "", 'as_percentage' => true);

	$chart['legend_bg'] = array('bg_color' => "ffffff", 'bg_alpha' => 0, 'border_color' => "000000", 'border_alpha' => 0, 'border_thickness' => 0);

	$chart['legend_label'] = array('layout' => "horizontal", 'bullet' => "square", 'font' => "verdana", 'bold' => false, 'size' => 11, 'color' => "333333", 'alpha' => 85 );
	$chart['legend_rect'] = array('x' => 5, 'y' => 190, 'width' => 280, 'height' => 50, 'margin' => 3);

	$chart['series_color'] = array("00ff88", "ffaa00","44aaff", "aa00ff", "ddaa41", "ff8811", "4d4d4d");
	$chart['series_explode'] = $_seriesexplode;

	SendChartData($chart);
	exit;
}

$interface->staffHeader($_SWIFT["language"]["troubleshooter"]." &gt; ".$_SWIFT["language"]["reports"], 6);

$interface->staffNavBar('<a href="index.php?_m=troubleshooter&_a=managesteps" title="'.$_SWIFT["language"]["managesteps"].'">'.$_SWIFT["language"]["troubleshooter"].'</a> &raquo; <a href="index.php?_m=troubleshooter&_a=reports&type=popularcategories" title="'.$_SWIFT["language"]["reports"].'">'.$_SWIFT["language"]["reports"].'</a> &raquo; <a href="index.php?_m=troubleshooter&_a=reports&type=popularsteps" title="'.$_SWIFT["language"]["popularsteps"].'">'.$_SWIFT["language"]["popularsteps"].'</a>', "", 6);

?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="300" align="left" valign="top">
<?
	echo InsertChart($_SWIFT["swiftpath"]."includes/Graph/charts.swf", "index.php?_m=troubleshooter&_a=reports&type=popularsteps&do=chart", 300, 350, "666666", true);
?>
</td>
<td align="left" valign="top">
<table width="100%"  border="0" cellspacing="1" cellpadding="3" class="tborder">
<tr class="tabletitlerow">
<td>&nbsp;<?=$_SWIFT["language"]["steptitle"]?></td>
<td width="60" align="center">&nbsp;<?=$_SWIFT["language"]["views"]?></td>
</tr>
<?
foreach ($_categories as $key=>$val)
{
	?>
	<tr class="<?=getRowBG()?>">
	<td>&nbsp;<a href="index.php?_m=troubleshooter&_a=editstep&troubleshooterid=<?=$val["troubleshooterid"]?>"><img src="<?=$_SWIFT["themepath"]?>icon_bluebigdot.gif" border="0" align="absmiddle" /> <?=$val["subject"]?></a></td>
	<td width="60" align="center">&nbsp;<?=$val["views"]?></td>
	</tr>
	<?
}
?>
</table>
</td>
</tr>
</table>
<?

$interface->staffFooter();

?>